package com.luhongda.music.utils;

import cn.hutool.core.lang.Console;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class DeepSeekUtils {

    public static void main(String[] args) {
        Console.log(deepSeekQuery("龙卷风.mp3，按照json格式返回歌手，曲名、所在专辑、风格、年份、音轨号"));
    }

    public static String deepSeekQuery(String question) {
        JSONObject req = new JSONObject();
        req.set("model", "deepseek-chat");
        req.set("stream", false);
        JSONObject message = new JSONObject();
        message.set("role", "system");
        message.set("content", question);
        JSONArray array = new JSONArray();
        array.add(message);
        req.set("messages", array);
        JSONObject res;
        try (HttpResponse httpResponse = HttpRequest.post("https://api.deepseek.com/chat/completions").header("Content-Type", "application/json").header("Authorization", "Bearer sk-5576c7d00cab44949a2ffac2c8cc7d60").body(req.toString()).execute()) {
            Console.log(JSONUtil.parseObj(httpResponse.body()));
            res = JSONUtil.parseObj(httpResponse.body());
        }
        return res.getJSONArray("choices").toString();
    }
}
